// 封装获取频道列表的逻辑
import { useState,useEffect } from "react"
import { getArticleChannels} from '@/apis/article'

function useChannel(){
    // 1.获取频道列表的所有逻辑
    // 获取频道数据
    const [channels, setChannels] = useState([])
    useEffect(() => {
        const getChannels = async () => {
            const { data: { channels } } = await getArticleChannels()
            setChannels(channels)
        }
        getChannels()
    }, [])
    // 2.把组件中要用到的数据return出去
    return {
        channels
    }
}

export default useChannel